﻿using Abp.Extensions;
using Microsoft.Extensions.Configuration;
using Mt.Site.Core.Security;

namespace Mt.Site.Core.Configuration
{
    public static class AppConfigurationsExtensions
    {
        public static string GetConnectionStringByAutoDecrypt(this IConfiguration configuration, string name)
        {
            var str = configuration["ConnectionStrings:" + name];
            var isEncode = configuration["App:EncodeSqlString"];
            if (isEncode != "true" || str.IsNullOrEmpty())
            {
                return str;
            }

            return SimpleStringCipherHelper.Decrypt(str);
        }
    }
}
